//
//  KKFollowVC.m
//  DoMi
//
//  Created by 康凯 on 2016/12/19.
//  Copyright © 2016年 kk. All rights reserved.
//

#import "KKFollowVC.h"
#import "KKFollowCell.h"
#import "KKMyHttp.h"

@interface KKFollowVC ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) NSArray *followDatas;
@end

@implementation KKFollowVC

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setNavBlack];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=self.navTitle;
    if([self.navTitle isEqualToString:@"关注"]){
        self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(getFollowList)];
    }else{
        self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(getFanList)];
    }
    
    [self.tableView.mj_header beginRefreshing];
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    self.tableView.rowHeight=78;
    [self.tableView registerNib:[UINib nibWithNibName:@"KKFollowCell" bundle:nil] forCellReuseIdentifier:@"KKFollowCell"];
}

#pragma mark tableview代理
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    KKFollowCell *follow=(KKFollowCell *)cell;
    follow.followClickBlock=^(){
        [self.tableView.mj_header beginRefreshing];
    };
    if([self.navTitle isEqualToString:@"关注"]){
        [follow initData:self.followDatas[indexPath.row]];
    }else{
        [follow initFansData:self.followDatas[indexPath.row]];
    }
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.followDatas.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [tableView dequeueReusableCellWithIdentifier:@"KKFollowCell"];
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 8;
}
#pragma mark 接口--关注列表
-(void)getFollowList{
    [KKMyHttp getFollowList:self.userId success:^(id data) {
        self.followDatas=data;
        [self.tableView reloadData];
        [self.tableView.mj_header endRefreshing];
    } failure:^(NSError *error) {
        [self.tableView.mj_header endRefreshing];
    }];
}
#pragma mark 接口--粉丝列表
-(void)getFanList{
    [KKMyHttp getFanList:self.userId success:^(id data) {
        self.followDatas=data;
        [self.tableView reloadData];
        [self.tableView.mj_header endRefreshing];
    } failure:^(NSError *error) {
        [self.tableView.mj_header endRefreshing];
    }];
}
@end
